package com.ds.lens.data.controller;

import com.ds.lens.data.service.LensIntegrationService;
import com.ds.lens.data.vo.BaseOutVO;
import com.ds.lens.data.vo.enums.DataCommonVOMessageEnum;
import com.ds.lens.data.vo.factory.VOFactory;
import com.ds.lens.data.vo.in.PagedConditionInVO;
import com.ds.lens.data.vo.in.v2.integration.LensIntegrationListInVO;
import com.ds.lens.data.vo.out.PageResult;
import com.ds.lens.data.vo.out.v2.integration.LensIntegrationDetailOutVO;
import com.ds.lens.data.vo.out.v2.integration.LensIntegrationOutVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * Description:
 *
 * @author WeiShaoying
 * @date 2019-11-04
 */
@Slf4j
@RestController
@Api(value = "Lens integration controller")
@RequestMapping(produces = {"application/json;charset=UTF-8"})
public class LensIntegrationController {

    @Autowired
    private LensIntegrationService lensIntegrationService;

    /**
     * Paging for query integrations
     *
     * @param inVO conditions
     * @return BaseOutVO object
     */
    @ApiOperation(value = "Paging for query integrations")
    @PostMapping(value = "/lens/integrations")
    public BaseOutVO getLensIntegrations(@RequestBody @Valid PagedConditionInVO<LensIntegrationListInVO> inVO) {
        PageResult<LensIntegrationOutVO> vo = lensIntegrationService.findLensIntegrationsByPage(inVO);
        if (null != vo) {
            return VOFactory.getSuccessBaseOutVO(vo);
        }
        return VOFactory.getBaseOutVO(DataCommonVOMessageEnum.COMMON_FAILED.getCode(), DataCommonVOMessageEnum.COMMON_FAILED.getMessage());
    }

    /**
     * Query integration information
     *
     * @param id primary key
     * @return BaseOutVO object
     */
    @ApiOperation(value = "Query integration information")
    @GetMapping(value = "/lens/integration")
    public BaseOutVO getLensIntegrationById(@RequestParam("id") Long id) {
        LensIntegrationDetailOutVO vo = lensIntegrationService.findLensIntegrationsById(id);
        if (null != vo) {
            return VOFactory.getSuccessBaseOutVO(vo);
        }
        return VOFactory.getBaseOutVO(DataCommonVOMessageEnum.COMMON_FAILED.getCode(), DataCommonVOMessageEnum.COMMON_FAILED.getMessage());
    }


    /**
     * Query integration
     *
     * @return BaseOutVO object
     */
    @ApiOperation(value = "Query integration information")
    @GetMapping(value = "/lens/integration/menus")
    public BaseOutVO getLensIntegrationById() {
        List<LensIntegrationOutVO> vos= lensIntegrationService.findLensIntegrationMenu();
        if (CollectionUtils.isNotEmpty(vos)) {
            return VOFactory.getSuccessBaseOutVO(vos);
        }
        return VOFactory.getBaseOutVO(DataCommonVOMessageEnum.COMMON_FAILED.getCode(), DataCommonVOMessageEnum.COMMON_FAILED.getMessage());
    }

}
